<template>
  <div id="pnr-list" class="card col-12 px-0 mt-5">
    <nav aria-label="breadcrumb" role="navigation">
      <ol class="breadcrumb">
        <li class="breadcrumb-item ms-1">
          <router-link to="/h5/tools/pnrs">PNR</router-link>
        </li>
        <li class="breadcrumb-item active">列表</li>
        <span class="ms-auto me-2" @click.stop="back()">返回</span>
      </ol>
    </nav>
    <template v-if="filterShowing">
      <div class="card-body mt-2 card-outline-primary">
        <form>
          <div class="row mb-2">
            <input
              class="form-control"
              type="text"
              placeholder="编码"
              v-model="pnrNo"
            />
          </div>
          <div class="row mb-2 d-none">
            <input
              class="form-control"
              type="text"
              placeholder="航司"
              v-model="carrier"
            />
          </div>
          <div class="row mb-2 d-none">
            <input
              class="form-control"
              type="text"
              placeholder="用户名"
              v-model="etermUsername"
            />
          </div>
          <div class="row mb-2">
            <my-date-picker
              :id="'beginDate0'"
              :class="'form-control'"
              :placeholder="'开始日期'"
              v-model="beginDate"
            ></my-date-picker>
          </div>
          <div class="row mb-2">
            <my-date-picker
              :id="'endDate0'"
              :class="'form-control'"
              :placeholder="'截止日期'"
              v-model="endDate"
            ></my-date-picker>
          </div>
          <div class="row mb-2 d-none">
            <select v-model="dzStatus" class="form-select">
              <option value="-1">全部</option>
              <option value="0">未开票</option>
              <option value="1">已开票</option>
            </select>
          </div>
          <div class="row mb-2 d-none">
            <select v-model="orderBy" class="form-select">
              <option value="0">ID降序</option>
              <option value="1">人数降序</option>
              <option value="2">用户名降序</option>
              <option value="3">状态降序</option>
            </select>
          </div>
          <div class="row mb-2">
            <select v-model.number="dataMode" class="form-select">
              <option value="0">当前</option>
              <option value="1">历史</option>
            </select>
          </div>
        </form>
      </div>
      <div class="card-footer text-center">
       
        <button
          type="button"
          class="btn btn-primary"
          @click.stop="hideFilter()"
        >
          确定
        </button>
         <button
          type="button"
          class="btn btn-secondary"
          @click.stop="resetFilter()"
        >
          重置
        </button>
      </div>
    </template>
    <template v-else>
      <div class="card-body py-1">
        <button
          type="button"
          class="btn btn-primary float-end"
          @click.stop="showFilter()"
        >
          查找
        </button>
      </div>
      <table class="table table-sm table-striped">
        <thead>
          <tr>
            <th>编码</th>
            <th class="">行程</th>
            <th class="">段数</th>
            <th>状态</th>
            <th>人数</th>
            <th>用户名</th>
            <th class="d-none">CTCM</th>
            <th class="d-none">联系电话</th>
            <th class="d-none"></th>
            <th class="d-none">生成时间</th>
            <th class="d-none">更新时间</th>
            <th></th>
          </tr>
        </thead>
        <tbody>
          <tr
            v-for="info in dataList"
            :key="info.id"
            @click.stop="showDetail(info)"
          >
            <td>{{ info.pnrNo }}</td>
            <td class="hidden-md-down small">
              {{ info.dport }}{{ info.aport }} {{ info.ddate }}
            </td>
            <td class="hidden-md-down small">{{ info.segCount }}</td>
            <td>
              <small>{{ info.segStatus }}</small>
            </td>
            <td>{{ info.psgCount }}</td>
            <td>{{ info.etermUsername }}</td>
            <td class="d-none">
              <small>{{ info.ctcmCount }}</small>
            </td>
            <td class="d-none">
              <small>{{ info.linkphone }}</small>
            </td>
            <td class="d-none">
              <small>{{ info.bookOfficeNo }}</small>
            </td>
            <td class="d-none">
              <small>{{ info.createTime }}</small>
            </td>
            <td class="d-none">
              <small>{{ info.lastUpdate }}</small>
            </td>
            <td><i class="fa fa-angle-right" aria-hidden="true"></i></td>
          </tr>
        </tbody>
      </table>
      <div class="card-block">
        <my-pagination
          name="pagination"
          :row-count="sc.rowCount"
          :page-total="sc.pageTotal"
          :page-no="sc.pageNo"
          @next-page="nextPage"
          @prev-page="prevPage"
          @direct-page="directPage"
        ></my-pagination>
      </div>
    </template>
  </div>
</template>

<script>
import MyPagination from "@/components/my-pagination_h5.vue";
import MyDatePicker from "@/components/my-datepicker.vue";
import { searchPnr, searchPnrUsed, createPnrMonitor } from "@/api/misc.js";

export default {
  name: "PnrList",
  components: {
    "my-pagination": MyPagination,
    MyDatePicker,
  },
  data() {
    return {
      filterShowing: false,

      dataList: [],
      sc: {
        rowCount: 0,
        pageNo: 1,
        pageSize: 10,
        pageTotal: 0,
      },
      etermUsername: "",
      pnrNo: "",
      beginDate: "",
      endDate: "",
      dzStatus: -1,
      carrier: "",
      orderBy: 0,
      dataMode: 0,
    };
  },
  mounted: function () {
    this.$store.commit("setWorkMode", "h5");
    this.search();
  },
  methods: {
    back: function () {
      this.$router.go(-1);
    },
    showErrMsg: function (msg, msgType) {
      this.$store.dispatch("showAlertMsg", {
        errMsg: msg,
        errMsgType: msgType,
      });
    },
    showLoading: function (loadingText) {
      this.$store.commit("showLoading", {
        loading: true,
        loadingText: loadingText,
      });
    },
    hideLoading: function () {
      this.$store.commit("showLoading", {
        loading: false,
      });
    },
    reset: function () {
      this.etermUsername = "";
      this.pnrNo = "";
      this.sc.pageNo = 1;
    },
    search: function () {
      this.showLoading();

      var beginDate = this.beginDate;
      if (beginDate === "") {
        beginDate = null;
      }

      var endDate = this.endDate;
      if (endDate === "") {
        endDate = null;
      }

      var params = {
        "sc.pageNo": this.sc.pageNo,
        "sc.pageSize": this.sc.pageSize,
        "sc.pnrNo": this.pnrNo,
        "sc.etermUsername": this.etermUsername,
        "sc.beginDate": beginDate,
        "sc.endDate": endDate,
        "sc.orderBy": this.orderBy,
        "sc.dzStatus": this.dzStatus,
        "sc.carrier": this.carrier,
      };

      if (this.dataMode === 0) {
        searchPnr(
          params,
          (jsonResult) => {
            this.dataList = jsonResult.dataList;
            this.sc = jsonResult.page;
          },
          () => {
            this.hideLoading();
          }
        );
      } else {
        searchPnrUsed(
          params,
          (jsonResult) => {
            this.dataList = jsonResult.dataList;
            this.sc = jsonResult.page;
          },
          () => {
            this.hideLoading();
          }
        );
      }
    },
    showDetail: function (info) {
      this.$store.commit("setPnrDetail", info);
      var path = "/h5/tools/pnr/" + info.id;
      this.$router.push(path);
    },
    prevPage: function () {
      this.sc.pageNo = this.sc.pageNo - 1;
      if (this.sc.pageNo < 1) this.sc.pageNo = 1;
      this.search();
    },
    nextPage: function () {
      this.sc.pageNo = this.sc.pageNo + 1;
      this.search();
    },
    directPage: function (pageNo) {
      this.sc.pageNo = pageNo;
      this.search();
    },
    showFilter: function () {
      this.filterShowing = true;
    },
    hideFilter: function () {
      this.filterShowing = false;
      this.search();
    },
    resetFilter: function () {
      this.etermUsername = "";
      this.pnrNo = "";
      this.beginDate = "";
      this.endDate = "";
      this.orderBy = 0;
      this.carrier = "";
      this.dzStatus = -1;
      this.dataMode = 0;
    },
  },
};
</script>
